home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / Z2.PYT < prev    next >
Encoding:
Text File  |  2000-06-30  |  22.8 KB  |  727 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64. """Zope 2 ZServer start-up file
  65.  
  66. Usage: %(program)s [options] [environment settings]
  67.  
  68. Options:
  69.  
  70.   -h
  71.  
  72.     Output this text.
  73.  
  74.   -z path
  75.  
  76.     The location of the Zope installation.
  77.     The default is the location of this script, %(here)s.
  78.  
  79.   -Z path
  80.  
  81.     Unix only! This option is ignored on windows.
  82.  
  83.     If this option is specified, a separate managemnt process will
  84.     be created that restarts Zope after a shutdown (or crash).
  85.     The path must point to a pid file that the process will record its
  86.     process id in. The path may be relative, in which case it will be
  87.     relative to the Zope location.
  88.  
  89.     To prevent use of a separate management process, provide an
  90.     empty string: -Z ''
  91.  
  92.   -t n
  93.  
  94.     The number of threads to use, if ZODB3 is used. The default is
  95.     %(NUMBER_OF_THREADS)s.
  96.  
  97.   -i n
  98.  
  99.     Set the interpreter check interval. This integer value
  100.     determines how often the interpreter checks for periodic things
  101.     such as thread switches and signal handlers. The Zope default
  102.     is 120, but you may want to experiment with other values that
  103.     may increase performance in your particular environment.
  104.  
  105.   -D
  106.  
  107.     Run in Zope debug mode.  This causes the Zope process not to
  108.     detach from the controlling terminal, and is equivalent to
  109.     supplying the environment variable setting Z_DEBUG_MODE=1
  110.  
  111.   -a ipaddress
  112.  
  113.     The IP address to listen on.  If this is an empty string
  114.     (e.g. -a ''), then all addresses on the machine are used. The
  115.     default is %(IP_ADDRESS)s.
  116.  
  117.   -d ipaddress
  118.  
  119.     IP address of your DNS server. If this is an empty string
  120.     (e.g. -d ''), then IP addresses will not be logged. If you have
  121.     DNS service on your local machine then you can set this to
  122.     127.0.0.1.  The default is: %(DNS_IP)s.
  123.     
  124.   -u username or uid number
  125.   
  126.     The username to run ZServer as. You may want to run ZServer as 'nobody'
  127.     or some other user with limited resouces. The only works under Unix, and
  128.     if ZServer is started by root. The default is: %(UID)s
  129.  
  130.   -P [ipaddress:]number
  131.  
  132.     Set the web, ftp and monitor port numbers simultaneously
  133.     as offsets from the number.  The web port number will be number+80.
  134.     The FTP port number will be number+21.  The monitor port number will
  135.     be number+99.
  136.  
  137.     The number can be preeceeded by an ip address follwed by a colon
  138.     to specify an address to listen on. This allows different servers
  139.     to listen on different addresses.
  140.  
  141.     Multiple -P options can be provided to run multiple sets of servers.
  142.     
  143.   -w port
  144.   
  145.     The Web server (HTTP) port.  This defaults to %(HTTP_PORT)s. The
  146.     standard port for HTTP services is 80.  If this is a dash
  147.     (e.g. -w -), then HTTP is disabled.
  148.  
  149.     The number can be preeceeded by an ip address follwed by a colon
  150.     to specify an address to listen on. This allows different servers
  151.     to listen on different addresses.
  152.  
  153.     Multiple -w options can be provided to run multiple servers.
  154.  
  155.   -f port
  156.   
  157.     The FTP port.  If this is a dash (e.g. -f -), then FTP
  158.     is disabled.  The standard port for FTP services is 21.  The
  159.     default is %(FTP_PORT)s.
  160.  
  161.     The port can be preeceeded by an ip address follwed by a colon
  162.     to specify an address to listen on. This allows different servers
  163.     to listen on different addresses.
  164.  
  165.     Multiple -f options can be provided to run multiple servers.
  166.  
  167.   -p path
  168.  
  169.     Path to the PCGI resource file.  The default value is
  170.     %(PCGI_FILE)s, relative to the Zope location.  If this is a dash
  171.     (-p -) or the file does not exist, then PCGI is disabled.
  172.  
  173.   -F path_or_port
  174.  
  175.     Either a port number (for inet sockets) or a path name (for unix
  176.     domain sockets) for the FastCGI Server.  If the flag and value are
  177.     not specified then the FastCGI Server is disabled.
  178.  
  179.   -m port
  180.   
  181.     The secure monitor server port. If this is a dash
  182.     (-m -), then the monitor server is disabled. The monitor server
  183.     allows interactive Python style access to a running ZServer. To
  184.     access the server see medusa/monitor_client.py or
  185.     medusa/monitor_client_win32.py. The monitor server password is the
  186.     same as the Zope super manager password set in the 'access'
  187.     file. The default is %(MONITOR_PORT)s.
  188.  
  189.     The port can be preeceeded by an ip address follwed by a colon
  190.     to specify an address to listen on. This allows different servers
  191.     to listen on different addresses.
  192.  
  193.     Multiple -m options can be provided to run multiple servers.
  194.  
  195.   -l path
  196.  
  197.     Path to the ZServer log file. If this is a relative path then the
  198.     log file will be written to the 'var' directory. The default is
  199.     %(LOG_FILE)s. 
  200.  
  201.   -r
  202.     
  203.     Run ZServer is read-only mode. ZServer won't write anything to disk.
  204.     No log files, no pid files, nothing. This means that you can't do a
  205.     lot of stuff like use PCGI, and zdaemon. ZServer will log hits to
  206.     STDOUT and zLOG will log to STDERR.
  207.  
  208.   -L
  209.   
  210.     Enable locale (internationalization) support. The value passed for
  211.     this option should be the name of the locale to be used (see your
  212.     operating system documentation for locale information specific to
  213.     your system). If an empty string is passed for this option (-L ''),
  214.     Zope will set the locale to the user's default setting (typically
  215.     specified in the $LANG environment variable). If your Python
  216.     installation does not support the locale module, the requested
  217.     locale is not supported by your system or an empty string was
  218.     passed but no default locale can be found, an error will be raised
  219.     and Zope will not start.
  220.  
  221.   -X
  222.  
  223.     Disable servers. This might be used to effectively disable all
  224.     default server settings or previous server settings in the option
  225.     list before providing new settings. For example to provide just a
  226.     web server:
  227.  
  228.       %(program)s -X -w80
  229.       
  230.   -M file
  231.  
  232.     Save detailed logging information to the given file.
  233.     This log includes separate entries for:
  234.  
  235.       - The start of a request,
  236.       - The start of processing the request in an application thread,
  237.       - The start of response output, and
  238.       - The end of the request.
  239.  
  240. Environment settings are of the form: NAME=VALUE.
  241.  
  242. Note: you *must* use Python 1.5.2 or later!
  243. """
  244.  
  245.  
  246. # This is required path hackery for the win32 binary distribution
  247. # that ensures that the bundled python libraries are used. In a
  248. # win32 binary distribution, the installer will have replaced the
  249. # marker string with the actual software home. If that has not
  250. # happened, then the path munging code is skipped.
  251. swhome=r'INSERT_SOFTWARE_HOME'
  252. if swhome != 'INSERT_SOFTWARE_HOME':
  253.     import sys
  254.     sys.path.insert(0, '%s/lib/python' % swhome)
  255.     sys.path.insert(1, '%s/bin/lib' % swhome)
  256.     sys.path.insert(2, '%s/bin/lib/plat-win' % swhome)
  257.     sys.path.insert(3, '%s/bin/lib/win32' % swhome)
  258.     sys.path.insert(4, '%s/bin/lib/win32/lib' % swhome)
  259.     sys.path.insert(5, '%s' % swhome)
  260.  
  261.  
  262. import os, sys, getopt, string
  263.  
  264. sys.setcheckinterval(120)
  265.  
  266.  
  267. program=sys.argv[0]
  268. here=os.path.join(os.getcwd(), os.path.split(program)[0])
  269. Zpid=''
  270.  
  271. ########################################################################
  272. # Configuration section
  273.  
  274. ## General configuration options
  275. ##
  276.  
  277. # If you want run as a daemon, then uncomment the line below:
  278. if sys.platform=='win32': Zpid=''
  279. else: Zpid='zProcessManager.pid'
  280.  
  281. # This is the IP address of the network interface you want your servers to
  282. # be visible from.  This can be changed to '' to listen on all interfaces.
  283. IP_ADDRESS=''
  284.  
  285. # IP address of your DNS server. Set to '' if you do not want to resolve
  286. # IP addresses. If you have DNS service on your local machine then you can
  287. # set this to '127.0.0.1'
  288. DNS_IP=''
  289.  
  290. # User id to run ZServer as. Note that this only works under Unix, and if
  291. # ZServer is started by root.
  292. UID='nobody'
  293.  
  294. # Log file location. If this is a relative path, then it is joined the
  295. # the 'var' directory.
  296. LOG_FILE='Z2.log'
  297.  
  298. ## HTTP configuration
  299. ##
  300.  
  301. # Port for HTTP Server. The standard port for HTTP services is 80.
  302. HTTP_PORT=8080
  303.  
  304. # HTTP enivornment settings.
  305. HTTP_ENV={}
  306.  
  307. ## FTP configuration
  308.  
  309. # Port for the FTP Server. The standard port for FTP services is 21.
  310. FTP_PORT=8021
  311.  
  312. ## PCGI configuration
  313.  
  314. # You can configure the PCGI server manually, or have it read its
  315. # configuration information from a PCGI info file.
  316. PCGI_FILE='Zope.cgi'
  317.  
  318. ## Monitor configuration
  319. MONITOR_PORT=8099
  320.  
  321. # Module to be published, which must be Main or Zope
  322. MODULE='Zope'
  323.  
  324. # The size of the thread pool, if ZODB3 is used.
  325. NUMBER_OF_THREADS=4
  326.  
  327.  
  328. # Localization support
  329. LOCALE_ID=None
  330.  
  331.  
  332.  
  333. # Socket path or port for the FastCGI Server
  334. FCGI_PORT=None
  335.  
  336. # Detailed log file
  337. DETAILED_LOG_FILE=''
  338.  
  339. #
  340. ########################################################################
  341.  
  342. ########################################################################
  343. # Handle command-line arguments:
  344.  
  345. def server_info(old, v, offset=0):
  346.     # interpret v as a port or address/port and get new value
  347.     if v == '-': v=''
  348.     l=string.find(v, ':')
  349.     if l >= 0:
  350.         a=v[:l]
  351.         v=v[l+1:]
  352.     else:
  353.         a=IP_ADDRESS
  354.  
  355.     if not v: return v
  356.         
  357.     try: 
  358.         v=string.atoi(v)
  359.         if v < 0: raise 'Invalid port', v
  360.         v=v+offset
  361.     except: raise 'Invalid port', v
  362.  
  363.     if type(old) is type(0): old=[(a,v)]
  364.     else: old.append((a,v))
  365.  
  366.     return old    
  367.     
  368.  
  369. try:
  370.     if string.split(sys.version)[0] < '1.5.2':
  371.         raise 'Invalid python version', string.split(sys.version)[0]
  372.  
  373.     opts, args = getopt.getopt(sys.argv[1:],
  374.                                'hz:Z:t:i:a:d:u:w:f:p:m:Sl:2DP:rF:L:XM:')
  375.  
  376.     DEBUG=0
  377.     READ_ONLY=0
  378.     
  379.     # Get environment variables
  380.     for a in args:
  381.         if string.find(a,'='):
  382.             a=string.split(a,'=')
  383.             o=a[0]
  384.             v=string.join(a[1:],'=')
  385.             if o: 
  386.               os.environ[o]=v
  387.               HTTP_ENV[o]=v
  388.         else:
  389.             raise 'Invalid argument', a
  390.  
  391.     for o, v in opts:
  392.         if o=='-z': here=v
  393.         elif o=='-Z':
  394.             if v=='-': v=''
  395.             Zpid=v
  396.         elif o=='-r': READ_ONLY=1
  397.         elif o=='-t':
  398.             try: v=string.atoi(v)
  399.             except: raise 'Invalid number of threads', v
  400.             NUMBER_OF_THREADS=v
  401.  
  402.         elif o=='-i':
  403.             try: v=string.atoi(v)
  404.             except: raise 'Invalid value for -i option', v
  405.             sys.setcheckinterval(v)
  406.  
  407.         elif o=='-a': IP_ADDRESS=v
  408.         elif o=='-d':
  409.             if v=='-': v=''
  410.             DNS_IP=v
  411.         elif o=='-u': UID=v
  412.         elif o=='-D':
  413.             os.environ['Z_DEBUG_MODE']='1'
  414.             DEBUG=1
  415.         elif o=='-S': sys.ZMANAGED=1
  416.         elif o=='-X':
  417.             MONITOR_PORT=HTTP_PORT=FTP_PORT=FCGI_PORT=0
  418.             PCGI_FILE=''
  419.         elif o=='-m':
  420.             MONITOR_PORT=server_info(MONITOR_PORT, v)
  421.         elif o=='-w':
  422.             HTTP_PORT=server_info(HTTP_PORT, v)
  423.         elif o=='-f':
  424.             FTP_PORT=server_info(FTP_PORT, v)
  425.         elif o=='-P':
  426.             MONITOR_PORT=server_info(MONITOR_PORT, v, 99)
  427.             HTTP_PORT=server_info(HTTP_PORT, v, 80)
  428.             FTP_PORT=server_info(FTP_PORT, v, 21)
  429.  
  430.         elif o=='-p':
  431.             if v=='-': v=''
  432.             PCGI_FILE=v
  433.         elif o=='-h':
  434.             print __doc__ % vars()
  435.             sys.exit(0)
  436.         elif o=='-2': MODULE='Main'
  437.         elif o=='-l': LOG_FILE=v
  438.         elif o=='-L':
  439.             if v: LOCALE_ID=v
  440.             else: LOCALE_ID=''
  441.         elif o=='-F':
  442.             if v=='-': v=''
  443.             FCGI_PORT=v
  444.         elif o=='-M': DETAILED_LOG_FILE=v
  445.  
  446.     __builtins__.__debug__=DEBUG
  447.  
  448. except SystemExit: sys.exit(0)
  449. except:
  450.     print __doc__ % vars()
  451.     print
  452.     print 'Error:'
  453.     print "%s: %s" % (sys.exc_type, sys.exc_value)
  454.     sys.exit(1)
  455.  
  456. if sys.platform=='win32': Zpid=''
  457.  
  458. #
  459. ########################################################################
  460.  
  461. ########################################################################
  462. # OK, let's get going!
  463.  
  464. # Jigger path:
  465. sys.path=[os.path.join(here,'lib','python'),here
  466.           ]+filter(None, sys.path)
  467.  
  468.  
  469.  
  470. # Try to set the locale if specified on the command
  471. # line. If the locale module is not available or the
  472. # requested locale is not supported by the local
  473. # machine, raise an error so that the user is made
  474. # aware of the problem.
  475.  
  476. def set_locale(val):
  477.     try:
  478.         import locale
  479.     except:
  480.         raise SystemExit, (
  481.             'The locale module could not be imported.\n' \
  482.             'To use localization options, you must ensure\n' \
  483.             'that the locale module is compiled into your\n' \
  484.             'Python installation.'
  485.             )
  486.     try:
  487.         locale.setlocale(locale.LC_ALL, val)
  488.     except:
  489.         raise SystemExit, (
  490.             'The specified locale is not supported by your system.\n' \
  491.             'See your operating system documentation for more\n' \
  492.             'information on locale support.'
  493.             )
  494. if LOCALE_ID is not None:
  495.     set_locale(LOCALE_ID)
  496.  
  497.  
  498. # from this point forward we can use the zope logger
  499.  
  500. # Import ZServer before we open the database or get at interesting
  501. # application code so that ZServer's asyncore gets to be the
  502. # official one. Also gets SOFTWARE_HOME and INSTANCE_HOME
  503. import ZServer
  504.  
  505. # CLIENT_HOME allows ZEO clients to easily keep distinct pid and
  506. # log files. This is currently an *experimental* feature, as I expect
  507. # that increasing ZEO deployment will cause bigger changes to the
  508. # way that z2.py works fairly soon.
  509. try:    CLIENT_HOME = os.environ['CLIENT_HOME']
  510. except: CLIENT_HOME = os.path.join(INSTANCE_HOME, 'var')
  511.  
  512. if Zpid and not READ_ONLY:
  513.     import zdaemon, App.FindHomes, posix
  514.     sys.ZMANAGED=1
  515.     
  516.     zdaemon.run(sys.argv, os.path.join(CLIENT_HOME, Zpid))
  517.  
  518. # Import logging support
  519. import zLOG
  520. import ZLogger
  521.  
  522. if READ_ONLY:
  523.     zLOG._stupid_dest=sys.stderr
  524. else:
  525.     zLOG.log_write = ZLogger.ZLogger.log_write
  526.  
  527. if DETAILED_LOG_FILE:
  528.     from ZServer import DebugLogger
  529.     logfile=os.path.join(CLIENT_HOME, DETAILED_LOG_FILE)
  530.     DebugLogger.log=DebugLogger.DebugLogger(logfile).log
  531.     
  532. # Import Zope (or Main)
  533. exec "import "+MODULE in {}
  534.  
  535. # Location of the ZServer log file. This file logs all ZServer activity.
  536. # You may wish to create different logs for different servers. See
  537. # medusa/logger.py for more information.
  538. if not os.path.isabs(LOG_FILE):
  539.     LOG_PATH=os.path.join(CLIENT_HOME, LOG_FILE)
  540. else:
  541.     LOG_PATH=LOG_FILE
  542.  
  543. # Location of the ZServer pid file. When ZServer starts up it will write
  544. # its PID to this file.
  545. PID_FILE=os.path.join(CLIENT_HOME, 'Z2.pid')
  546.  
  547.  
  548. # import ZServer stuff
  549.  
  550. # First, we need to increase the number of threads
  551. if MODULE=='Zope':
  552.     from ZServer import setNumberOfThreads
  553.     setNumberOfThreads(NUMBER_OF_THREADS)
  554.  
  555. from ZServer import resolver, logger, asyncore
  556.  
  557. from ZServer import zhttp_server, zhttp_handler
  558. from ZServer import PCGIServer,FTPServer,FCGIServer
  559.  
  560. from ZServer import secure_monitor_server
  561.  
  562. ## ZServer startup
  563. ##
  564.  
  565. # Resolver and Logger, used by other servers
  566. if DNS_IP:
  567.     rs = resolver.caching_resolver(DNS_IP)
  568. else:
  569.     rs=None
  570.  
  571. if READ_ONLY:
  572.     lg = logger.file_logger('-') # log to stdout
  573. elif os.environ.has_key('ZSYSLOG'):
  574.     lg = logger.syslog_logger(os.environ['ZSYSLOG'])
  575. elif os.environ.has_key('ZSYSLOG_SERVER'):
  576.     lg = logger.syslog_logger(string.split(os.environ['ZSYSLOG_SERVER'], ':'))
  577. else:
  578.     lg = logger.file_logger(LOG_PATH)
  579.  
  580. # HTTP Server
  581. if HTTP_PORT:
  582.     if type(HTTP_PORT) is type(0): HTTP_PORT=((IP_ADDRESS, HTTP_PORT),)
  583.     for address, port in HTTP_PORT:
  584.         hs = zhttp_server(
  585.             ip=address,
  586.             port=port,
  587.             resolver=rs,
  588.             logger_object=lg)
  589.  
  590.         # Handler for a published module. zhttp_handler takes 3 arguments:
  591.         # The name of the module to publish, and optionally the URI base
  592.         # which is basically the SCRIPT_NAME, and optionally a dictionary
  593.         # with CGI environment variables which override default
  594.         # settings. The URI base setting is useful when you want to
  595.         # publish more than one module with the same HTTP server. The CGI
  596.         # environment setting is useful when you want to proxy requests
  597.         # from another web server to ZServer, and would like the CGI
  598.         # environment to reflect the CGI environment of the other web
  599.         # server.    
  600.         zh = zhttp_handler(MODULE, '', HTTP_ENV)
  601.         hs.install_handler(zh)
  602.  
  603.  
  604. # FTP Server
  605. if FTP_PORT:
  606.     if type(FTP_PORT) is type(0): FTP_PORT=((IP_ADDRESS, FTP_PORT),)
  607.     for address, port in FTP_PORT:
  608.         FTPServer(
  609.            module=MODULE,
  610.            ip=address,
  611.            port=port,
  612.            resolver=rs,
  613.            logger_object=lg)
  614.  
  615. # PCGI Server
  616. if PCGI_FILE and not READ_ONLY:
  617.     PCGI_FILE=os.path.join(here, PCGI_FILE)
  618.     if os.path.exists(PCGI_FILE):
  619.         zpcgi = PCGIServer(
  620.             module=MODULE,
  621.             ip=IP_ADDRESS,
  622.             pcgi_file=PCGI_FILE,
  623.             resolver=rs,
  624.             logger_object=lg)
  625.  
  626.  
  627. # FastCGI Server
  628. if FCGI_PORT and not READ_ONLY:
  629.     fcgiPort = None
  630.     fcgiPath = None
  631.     try:
  632.         fcgiPort = string.atoi(FCGI_PORT)
  633.     except ValueError:
  634.         fcgiPath = FCGI_PORT
  635.     zfcgi = FCGIServer(module=MODULE,
  636.                        ip=IP_ADDRESS,
  637.                        port=fcgiPort,
  638.                        socket_file=fcgiPath,
  639.                        resolver=rs,
  640.                        logger_object=lg)
  641.  
  642.  
  643. # Monitor Server
  644. if MONITOR_PORT:
  645.     if type(MONITOR_PORT) is type(0): 
  646.         MONITOR_PORT=((IP_ADDRESS, MONITOR_PORT),)
  647.     for address, port in MONITOR_PORT:
  648.         from AccessControl.User import super
  649.         monitor=secure_monitor_server(
  650.             password=super._getPassword(),
  651.             hostname=address,
  652.             port=port)
  653.  
  654. # Try to set uid to "-u" -provided uid.
  655. # Try to set gid to  "-u" user's primary group. 
  656. # This will only work if this script is run by root.
  657. try:
  658.     import pwd
  659.     try:
  660.         gid = None
  661.         if type(UID) == type(""):
  662.             uid = pwd.getpwnam(UID)[2]
  663.             gid = pwd.getpwnam(UID)[3]
  664.         elif type(UID) == type(1):
  665.             uid = pwd.getpwuid(UID)[2]
  666.             gid = pwd.getpwuid(UID)[3]
  667.         else:
  668.             raise KeyError 
  669.         try:
  670.             if gid is not None:
  671.                 try:
  672.                     os.setgid(gid)
  673.                 except OSError:
  674.                     pass
  675.             os.setuid(uid)
  676.         except OSError:
  677.             pass
  678.     except KeyError:
  679.         zLOG.LOG("z2", zLOG.ERROR, ("can't find UID %s" % UID))
  680. except:
  681.     pass
  682.  
  683.  
  684.  
  685. # if it hasn't failed at this point, create a .pid file.
  686. if not READ_ONLY:
  687.     pf = open(PID_FILE, 'w')
  688.     pid=str(os.getpid())
  689.     try: pid=str(os.getppid())+' '+pid
  690.     except: pass
  691.     pf.write(pid)
  692.     pf.close()
  693.  
  694. # Start Medusa, Ye Hass!
  695. sys.ZServerExitCode=0
  696. asyncore.loop()
  697. sys.exit(sys.ZServerExitCode)
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.